import worker from '@ohos.worker'; // 导入worker模块
import { LoadAndScanXml } from "../scan/xmlScaner"
var parentPort = worker.parentPort; // 获取parentPort属性

import bytrace from "@ohos.bytrace"

// 接收宿主线程的数据 url 地址
parentPort.onmessage = function (e) { // 定义onmessage方法
    // console.error("Kee zx worker: onmessage");
    var data = e.data;
    switch(data.type) {
        case "normal":
            // console.error("Kee zx worker receive normal data");
            var src = data.data;
            // console.error("Kee zx worker: src = " + src);
            bytrace.startTrace("DynamicTrace", 102)
            var viewNode = LoadAndScanXml(src);
            bytrace.finishTrace("DynamicTrace", 102)
            // console.error("Kee zx worker: viewNode");
            parentPort.postMessage({type: "ViewNodeUpdate", data: viewNode}) // 返回值
            break;
        default:
            // console.error("Kee zx worker: data type error")
    }
}